home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / xcontact / parody / pstrings.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.9 KB  |  66 lines

  1. // -------- pstrings.h
  2.  
  3. #ifndef PSTRINGS_H
  4. #define PSTRINGS_H
  5.  
  6. #include <iostream.h>
  7. #include <string.h>
  8.  
  9. // ============================
  10. // BASIC-like pString Class
  11. // ============================
  12. class pString    {
  13.     char *sptr;
  14.     int length;
  15.     void putstr(char *s);
  16. public:
  17.     // -------- construct a null string
  18.     pString() { sptr = NULL; }
  19.     // --- construct with char * initializer
  20.     pString(char *s);
  21.     // ------- copy constructor
  22.     pString(pString& s);
  23.     // -------- construct with a size and fill character
  24.     pString(int len, char fill = 0);
  25.     // ------- destructor
  26.     ~pString() { delete sptr; }
  27.     // ------ return the length of a string
  28.     int Strlen() { return strlen(sptr); }
  29.     int Length() { return length; }
  30.     // ---- substring: right len chars
  31.     pString right(int len);
  32.     // ---- substring: left len chars
  33.     pString left(int len);
  34.     // ---- substring: middle len chars starting from where
  35.     pString mid(int len, int where);
  36.     int FindChar(unsigned char ch);
  37.     // ---------- assignment
  38.     pString& operator=(pString& s);
  39.     // ---------- conversion to char *
  40.     operator char *() { return sptr; }
  41.     // --- concatenation operator (str1 + str2;)
  42.     pString operator+(pString& s);
  43.     // --- concatenation operator (str1 += str2;)
  44.     void operator+=(pString& s) { *this = *this + s; }
  45.     // ------- relational operators
  46.     pBool operator==(pString& s)
  47.         { return (pBool) (strcmp(sptr,s.sptr) == 0); }
  48.     pBool operator!=(pString& s)
  49.         { return (pBool) (strcmp(sptr,s.sptr) != 0); }
  50.     pBool operator>(pString& s)
  51.         { return (pBool) (strcmp(sptr,s.sptr) > 0); }
  52.     pBool operator<(pString& s)
  53.         { return (pBool) (strcmp(sptr,s.sptr) < 0); }
  54.     pBool operator<=(pString& s)
  55.         { return (pBool) (!(*this > s)); }
  56.     pBool operator>=(pString& s)
  57.         { return (pBool) (!(*this < s)); }
  58.     // ------- subscript
  59.     char& operator[](int n) { return sptr[n]; }
  60.     // ------- stream I/O
  61.     friend ostream& operator<< (ostream& os, pString& str);
  62.     friend istream& operator>> (istream& is, pString& str);
  63. };
  64.  
  65. #endif
  66.